package jp.eisbahn.mgapi.api.check;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import jp.eisbahn.mgapi.api.NopResponse;
import jp.eisbahn.mgapi.api.Request;
import jp.eisbahn.mgapi.api.Response;
import jp.eisbahn.mgapi.api.Visibility;
import jp.eisbahn.mgapi.http.ContentType;
import jp.eisbahn.mgapi.http.HttpMethod;

/**
 * This class is a request class to access Check API.
 * @author Yoichiro Tanaka
 */
public class CheckRequest implements Request {

    /** The key. */
    private String key;
    /** The visibility. */
    private Visibility visibility;
    /** The group ID. */
    private String groupId;
    /** The title. */
    private String title;
    /** The description. */
    private String description;
    /** The comment. */
    private String comment;
    /** The content rating. */
    private boolean contentRating;
    /** The image URL. */
    private String image;
    /** The primary URL. */
    private String primaryUrl;
    /** The PC URL. */
    private String pcUrl;
    /** The smartphone URL. */
    private String smartphoneUrl;
    /** The mobile URL. */
    private String mobileUrl;
    /** The mobile Docomo URL. */
    private String mobileDocomoUrl;
    /** The mobile au URL. */
    private String mobileAuUrl;
    /** The mobile Softbank URL. */
    private String mobileSoftbankUrl;

    /*
     * (non-Javadoc)
     * @see jp.eisbahn.mgapi.api.Request#getUri()
     */
    @Override
    public final String getUri() {
        return "/share";
    }

    /*
     * (non-Javadoc)
     * @see jp.eisbahn.mgapi.api.Request#getHttpMethod()
     */
    @Override
    public final HttpMethod getHttpMethod() {
        return HttpMethod.POST;
    }

    /*
     * (non-Javadoc)
     * @see jp.eisbahn.mgapi.api.Request#getResponseClass()
     */
    @Override
    public final Class<? extends Response> getResponseClass() {
        return NopResponse.class;
    }

    /*
     * (non-Javadoc)
     * @see jp.eisbahn.mgapi.api.Request#getContentType()
     */
    @Override
    public final ContentType getContentType() {
        return ContentType.JSON;
    }

    /*
     * (non-Javadoc)
     * @see jp.eisbahn.mgapi.api.Request#getBodyStream()
     */
    @Override
    public final InputStream getBodyStream() {
        return null;
    }

    /*
     * (non-Javadoc)
     * @see jp.eisbahn.mgapi.api.Request#getParameterMap()
     */
    @Override
    public final Map<String, Object> getParameterMap() {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        putToMap(paramMap, "key", key);
        Map<String, Object> privacy = new HashMap<String, Object>();
        putToMap(privacy, "visibility", visibility.name());
        if (visibility.equals(Visibility.group)) {
            putToMap(privacy, "group", groupId);
        }
        putToMap(paramMap, "privacy", privacy);
        putToMap(paramMap, "title", title);
        putToMap(paramMap, "description", description);
        putToMap(paramMap, "comment", comment);
        if (contentRating) {
            putToMap(paramMap, "content_rating", "1");
        }
        putToMap(paramMap, "image", image);
        putToMap(paramMap, "primary_url", primaryUrl);
        putToMap(paramMap, "pc_url", pcUrl);
        putToMap(paramMap, "smartphone_url", smartphoneUrl);
        putToMap(paramMap, "mobile_url", mobileUrl);
        putToMap(paramMap, "mobile_docomo_url", mobileDocomoUrl);
        putToMap(paramMap, "mobile_au_url", mobileAuUrl);
        putToMap(paramMap, "mobile_softbank_url", mobileSoftbankUrl);
        return paramMap;
    }

    /**
     * Put the value to the specified map.
     * @param map The map object.
     * @param keyName The key name.
     * @param value The value to be set.
     */
    private void putToMap(
            final Map<String, Object> map,
            final String keyName,
            final Object value) {
        if (value != null) {
            map.put(keyName, value);
        }
    }

    /*
     * (non-Javadoc)
     * @see jp.eisbahn.mgapi.api.Request#getHeaderMap()
     */
    @Override
    public final Map<String, String> getHeaderMap() {
        return null;
    }

    /**
     * Set a new key.
     * @param newKey The key string.
     */
    public final void setKey(final String newKey) {
        key = newKey;
    }

    /**
     * Retrieve a key.
     * @return The key string.
     */
    public final String getKey() {
        return key;
    }

    /**
     * Set a new visibility.
     * @param newVisibility The visibility value.
     */
    public final void setVisibility(final Visibility newVisibility) {
        visibility = newVisibility;
    }

    /**
     * Retrieve the visibility.
     * @return The visibility value.
     */
    public final Visibility getVisibility() {
        return visibility;
    }

    /**
     * Set a new group ID.
     * @param newGroupId The group ID.
     */
    public final void setGroupId(final String newGroupId) {
        groupId = newGroupId;
    }

    /**
     * Retrieve the group ID.
     * @return The group ID.
     */
    public final String getGroupId() {
        return groupId;
    }

    /**
     * Set a title value.
     * @param newTitle The title to set
     */
    public final void setTitle(final String newTitle) {
        title = newTitle;
    }

    /**
     * Retrieve the title value.
     * @return The title value.
     */
    public final String getTitle() {
        return title;
    }

    /**
     * Set a description value.
     * @param newDescription The description to set
     */
    public final void setDescription(final String newDescription) {
        description = newDescription;
    }

    /**
     * Retrieve the description value.
     * @return The description value.
     */
    public final String getDescription() {
        return description;
    }

    /**
     * Set a comment value.
     * @param newComment The comment to set
     */
    public final void setComment(final String newComment) {
        comment = newComment;
    }

    /**
     * Retrieve the comment value.
     * @return The comment value.
     */
    public final String getComment() {
        return comment;
    }

    /**
     * Set a contentRating value.
     * @param newContentRating The contentRating to set
     */
    public final void setContentRating(final boolean newContentRating) {
        this.contentRating = newContentRating;
    }

    /**
     * Retrieve the contentRating value.
     * @return The contentRating value.
     */
    public final boolean isContentRating() {
        return contentRating;
    }

    /**
     * Set a image value.
     * @param newImage The image to set
     */
    public final void setImage(final String newImage) {
        this.image = newImage;
    }

    /**
     * Retrieve the image value.
     * @return The image value.
     */
    public final String getImage() {
        return image;
    }

    /**
     * Set a primaryUrl value.
     * @param newPrimaryUrl The primaryUrl to set
     */
    public final void setPrimaryUrl(final String newPrimaryUrl) {
        this.primaryUrl = newPrimaryUrl;
    }

    /**
     * Retrieve the primaryUrl value.
     * @return The primaryUrl value.
     */
    public final String getPrimaryUrl() {
        return primaryUrl;
    }

    /**
     * Set a pcUrl value.
     * @param newPcUrl The pcUrl to set
     */
    public final void setPcUrl(final String newPcUrl) {
        this.pcUrl = newPcUrl;
    }

    /**
     * Retrieve the pcUrl value.
     * @return The pcUrl value.
     */
    public final String getPcUrl() {
        return pcUrl;
    }

    /**
     * Set a smartphoneUrl value.
     * @param newSmartphoneUrl The smartphoneUrl to set
     */
    public final void setSmartphoneUrl(final String newSmartphoneUrl) {
        this.smartphoneUrl = newSmartphoneUrl;
    }

    /**
     * Retrieve the smartphoneUrl value.
     * @return The smartphoneUrl value.
     */
    public final String getSmartphoneUrl() {
        return smartphoneUrl;
    }

    /**
     * Set a mobileUrl value.
     * @param newMobileUrl The mobileUrl to set
     */
    public final void setMobileUrl(final String newMobileUrl) {
        this.mobileUrl = newMobileUrl;
    }

    /**
     * Retrieve the mobileUrl value.
     * @return The mobileUrl value.
     */
    public final String getMobileUrl() {
        return mobileUrl;
    }

    /**
     * Retrieve the mobileDocomoUrl value.
     * @return The mobileDocomoUrl value.
     */
    public final String getMobileDocomoUrl() {
        return mobileDocomoUrl;
    }

    /**
     * Set a mobileDocomoUrl value.
     * @param newMobileDocomoUrl The mobileDocomoUrl to set
     */
    public final void setMobileDocomoUrl(final String newMobileDocomoUrl) {
        this.mobileDocomoUrl = newMobileDocomoUrl;
    }

    /**
     * Retrieve the mobileAuUrl value.
     * @return The mobileAuUrl value.
     */
    public final String getMobileAuUrl() {
        return mobileAuUrl;
    }

    /**
     * Set a mobileAuUrl value.
     * @param newMobileAuUrl The mobileAuUrl to set
     */
    public final void setMobileAuUrl(final String newMobileAuUrl) {
        this.mobileAuUrl = newMobileAuUrl;
    }

    /**
     * Retrieve the mobileSoftbankUrl value.
     * @return The mobileSoftbankUrl value.
     */
    public final String getMobileSoftbankUrl() {
        return mobileSoftbankUrl;
    }

    /**
     * Set a mobileSoftbankUrl value.
     * @param newMobileSoftbankUrl The mobileSoftbankUrl to set
     */
    public final void setMobileSoftbankUrl(final String newMobileSoftbankUrl) {
        this.mobileSoftbankUrl = newMobileSoftbankUrl;
    }

}
